import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Date;

import org.junit.Before;
import org.junit.Test;

/**
 * 
 */

/**
 * @author user
 *
 */
public class TestTransport {
	
	Transport trans1;
	Transport trans2;
	Transport trans3;
	Transport trans4;
	Transport trans5;
	Transport trans6;
	Trajet trajet1;
	Trajet trajet2;
	Date d1;
	Date d2;
	Date d3;
	Date d4;
	Passager p1;
	Passager p2;
	ArrayList<Passager> passagers;
	ArrayList<Trajet> trajets;
	
	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		d1 = new Date(111, 10, 18, 12, 04);
		d2 = new Date(111, 11, 20, 12, 04);
		d3 = new Date(111, 10, 30, 14, 59);
		d4 = new Date(111, 12, 0, 1, 2);
		
		trajet1 = new Trajet(Villes.NEWYORK, Villes.PARIS, d1, d2);
		trajet2 = new Trajet(Villes.MARSEILLE, Villes.NICE, d3, d4);
		trajets = new ArrayList<Trajet>();		
		trajets.add(trajet1);
		trajets.add(trajet2);
		
		p1 = new Passager("maugard", "matthieu");
		p2 = new Passager("paeta", "suzy");
		
		passagers = new ArrayList<Passager>();
		passagers.add(p1);
		passagers.add(p2);
		
		trans1 = new Transport("avion1", 10, trajets, Types.AVION);

	}

	/**
	 * Test method for {@link Transport#getCapaciteMax()}.
	 */
	@Test
	public void testGetCapaciteMax() {
		assertEquals(10, trans1.getCapaciteMax());
	}

	/**
	 * Test method for {@link Transport#getTrajets()}.
	 */
	@Test
	public void testGetTrajets() {
		ArrayList<Trajet> getTraj = trans1.getTrajets();
		assertEquals(2, getTraj.size());
		assertEquals(trajet1, getTraj.get(0));
		assertEquals(trajet2, getTraj.get(1));
	}
	
	/**
	 * Test method for {@link Transport#ajouterTrajet(Trajet)}.
	 */
	@Test
	public void testAjouterTrajet() {
		Trajet trajet3 = new Trajet(Villes.NEWYORK, Villes.NICE, d1, d2);
		trans1.ajouterTrajet(trajet3);		
		assertEquals(3, trans1.getTrajets().size());
		assertEquals(trajet3, trans1.getTrajets().get(2));

	}

	/**
	 * Test method for {@link Transport#getType()}.
	 */
	@Test
	public void testGetType() {
		assertEquals(Types.AVION, trans1.getType());
	}

	/**
	 * Test method for {@link Transport#getNom()}.
	 */
	@Test
	public void testGetNom() {
		assertEquals("nom", trans1.getNom());
	}
	
    /**
     * 
     */
    @Test(expected=NullPointerException.class)
    public void testNullPointerException() {
    	trans3 = new Transport(null, 2, trajets, Types.BATEAU);
    	trans4 = new Transport("toto", 5, null, Types.TRAIN);
    	trans5 = new Transport("toto", 3, trajets, null);
    	trans1.ajouterTrajet(null);
    	trans2.setTrajets(null);
    	trans1.setNom(null);
    	trans2.setType(null);
    }

    /**
     * 
     */
    @Test(expected=IllegalArgumentException.class)
    public void testIllegalArgumentException(){
    	trans6 = new Transport("toto", -4, trajets, Types.AVION);
    	trans1.setCapaciteMax(-1);

    }
}
